/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.BpmnPackage;
import bpmn.SubProcess;
import bpmn.SubProcessType;
import bpmn.Transaction;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Sub Process</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.SubProcessImpl#getSubProcessType <em>Sub Process Type</em>}</li>
 *   <li>{@link bpmn.impl.SubProcessImpl#getIsATransaction <em>Is ATransaction</em>}</li>
 *   <li>{@link bpmn.impl.SubProcessImpl#getTransactionRef <em>Transaction Ref</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SubProcessImpl extends ActivityImpl implements SubProcess {
	/**
	 * The default value of the '{@link #getSubProcessType() <em>Sub Process Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubProcessType()
	 * @generated
	 * @ordered
	 */
	protected static final SubProcessType SUB_PROCESS_TYPE_EDEFAULT = SubProcessType.EMBEDDED;

	/**
	 * The cached value of the '{@link #getSubProcessType() <em>Sub Process Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubProcessType()
	 * @generated
	 * @ordered
	 */
	protected SubProcessType subProcessType = SUB_PROCESS_TYPE_EDEFAULT;

	/**
	 * The default value of the '{@link #getIsATransaction() <em>Is ATransaction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIsATransaction()
	 * @generated
	 * @ordered
	 */
	protected static final Boolean IS_ATRANSACTION_EDEFAULT = Boolean.FALSE;

	/**
	 * The cached value of the '{@link #getIsATransaction() <em>Is ATransaction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIsATransaction()
	 * @generated
	 * @ordered
	 */
	protected Boolean isATransaction = IS_ATRANSACTION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getTransactionRef() <em>Transaction Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTransactionRef()
	 * @generated
	 * @ordered
	 */
	protected Transaction transactionRef;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SubProcessImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.SUB_PROCESS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SubProcessType getSubProcessType() {
		return subProcessType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSubProcessType(SubProcessType newSubProcessType) {
		SubProcessType oldSubProcessType = subProcessType;
		subProcessType = newSubProcessType == null ? SUB_PROCESS_TYPE_EDEFAULT : newSubProcessType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.SUB_PROCESS__SUB_PROCESS_TYPE, oldSubProcessType, subProcessType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Boolean getIsATransaction() {
		return isATransaction;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIsATransaction(Boolean newIsATransaction) {
		Boolean oldIsATransaction = isATransaction;
		isATransaction = newIsATransaction;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.SUB_PROCESS__IS_ATRANSACTION, oldIsATransaction, isATransaction));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Transaction getTransactionRef() {
		if (transactionRef != null && transactionRef.eIsProxy()) {
			InternalEObject oldTransactionRef = (InternalEObject)transactionRef;
			transactionRef = (Transaction)eResolveProxy(oldTransactionRef);
			if (transactionRef != oldTransactionRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.SUB_PROCESS__TRANSACTION_REF, oldTransactionRef, transactionRef));
			}
		}
		return transactionRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Transaction basicGetTransactionRef() {
		return transactionRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTransactionRef(Transaction newTransactionRef) {
		Transaction oldTransactionRef = transactionRef;
		transactionRef = newTransactionRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.SUB_PROCESS__TRANSACTION_REF, oldTransactionRef, transactionRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.SUB_PROCESS__SUB_PROCESS_TYPE:
				return getSubProcessType();
			case BpmnPackage.SUB_PROCESS__IS_ATRANSACTION:
				return getIsATransaction();
			case BpmnPackage.SUB_PROCESS__TRANSACTION_REF:
				if (resolve) return getTransactionRef();
				return basicGetTransactionRef();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.SUB_PROCESS__SUB_PROCESS_TYPE:
				setSubProcessType((SubProcessType)newValue);
				return;
			case BpmnPackage.SUB_PROCESS__IS_ATRANSACTION:
				setIsATransaction((Boolean)newValue);
				return;
			case BpmnPackage.SUB_PROCESS__TRANSACTION_REF:
				setTransactionRef((Transaction)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.SUB_PROCESS__SUB_PROCESS_TYPE:
				setSubProcessType(SUB_PROCESS_TYPE_EDEFAULT);
				return;
			case BpmnPackage.SUB_PROCESS__IS_ATRANSACTION:
				setIsATransaction(IS_ATRANSACTION_EDEFAULT);
				return;
			case BpmnPackage.SUB_PROCESS__TRANSACTION_REF:
				setTransactionRef((Transaction)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.SUB_PROCESS__SUB_PROCESS_TYPE:
				return subProcessType != SUB_PROCESS_TYPE_EDEFAULT;
			case BpmnPackage.SUB_PROCESS__IS_ATRANSACTION:
				return IS_ATRANSACTION_EDEFAULT == null ? isATransaction != null : !IS_ATRANSACTION_EDEFAULT.equals(isATransaction);
			case BpmnPackage.SUB_PROCESS__TRANSACTION_REF:
				return transactionRef != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (SubProcessType: ");
		result.append(subProcessType);
		result.append(", IsATransaction: ");
		result.append(isATransaction);
		result.append(')');
		return result.toString();
	}

} //SubProcessImpl
